<script>

var forumlist = <?php echo xn_json_encode($forumlist_show);?>;

// 初始化值，选中的值
var tagids = <?php echo xn_json_encode($tagids);?>;
var action = '<?php echo $action;?>';

var jfid = $('select[name="fid"]');
var fid = <?php echo intval($fid); ?> || $('select[name="fid"]').val();
jfid.on('change', function() {
	var fid = jfid.val();
	fid_on_change(fid);
});

function fid_on_change(fid) {
	var s = '<table class="small nav_tag_list mb-2">';
	var forum = forumlist[fid];
	$.each(forum.tagcatelist, function(k, tagcate) {
		s += '<tr><td class="text-muted text-nowrap" align="right" valign="top">';
		s += tagcate.name;
		s += '：</td><td>';
		$.each(tagcate.taglist, function(k, tag) {
			s += '<a href="javascript:void(0);" class="tag_option ' + (xn.in_array(tag.tagid, tagids) || (tag.tagid == tagcate.defaulttagid && action == 'create') ? ' active' : '') + '" tagid="' + tag.tagid + '">' + tag.name + '</a>';
			s += '<input type="hidden" name="tagid[]" value="' + (xn.in_array(tag.tagid, tagids) || (tag.tagid == tagcate.defaulttagid && action == 'create') ? tag.tagid : '') + '" />';
		});
		s += '</td></tr>';
	});
	s += '</table>';
	$('#nav_tag_list_div').html(s);
}

fid_on_change(fid);

$('#nav_tag_list_div').on('click', 'a.tag_option', function() {
	var jthis = $(this);
	var tagid = jthis.attr('tagid');
	jthis.toggleClass('active');
	// 隐藏域
	var v = jthis.hasClass('active') ? tagid : '';
	jthis.next().attr('value', v);
});


// tag 选中区域。

</script>